﻿using Castle.MicroKernel;
using Codeflows.Tracking;

namespace Codeflows.Contrib.Windsor
{
    public class WindsorCodeflowTrackerFactory : ICodeflowTrackerFactory
    {
        private readonly IKernel _kernel;

        public WindsorCodeflowTrackerFactory(IKernel kernel)
        {
            _kernel = kernel;
        }

        public DisposableContext<ICodeflowTracker> CreateTracker()
        {
            var tracker = _kernel.Resolve<ICodeflowTracker>();

            return new DisposableContext<ICodeflowTracker>(tracker, instance => _kernel.ReleaseComponent(instance));
        }
    }
}